using System;
using System.Collections.Generic;
using System.Text;
using TVDesigner.Entities.DataProvider;
using System.Xml.Serialization;
using System.Xml;
using System.Collections;

namespace TVDesigner.Entities.Elements
{
    [XmlRoot("ProjectXlet")]
    public class ProjectXlet
    {
        private GenerateInstructions _GenerateInstructions;

        [NonSerialized()]
        private List<Screen> _Screens;
        private string _StartScreen;
        //private SerializableDictionary<string, string> _StaticScreenStringName;

        public ProjectXlet()
        {
            //_StaticScreenStringName = new SerializableDictionary<string, string>();
            _GenerateInstructions = new GenerateInstructions();
            _Screens = new List<Screen>();
        }

        #region Propriedades

        //[XmlElement("dictionary")]
        //public SerializableDictionary<string, string> StaticScreenStringName
        //{
        //    get { return _StaticScreenStringName; }
        //    set { _StaticScreenStringName = value; }
        //}
        [XmlAttributeAttribute("StartScreen")]
        public string StartScreen
        {
            get { return _StartScreen; }
            set { _StartScreen = value; }
        }

        [XmlElementAttribute("Screen")]
        public List<Screen> Screens
        {
            get { return _Screens; }
            set { _Screens = value; }
        }

        [XmlElementAttribute("GenerateInstructions")]
        public GenerateInstructions GenerateInstructions
        {
            get { return _GenerateInstructions; }
            set { _GenerateInstructions = value; }
        }

        [XmlAttributeAttribute("Name")]
        public string Name
        {
            get { return _GenerateInstructions.ProjectName; }
            set
            {
                _GenerateInstructions.ProjectName = value;
            }
        }
        public string NameStartedWithUpperCase
        {
            get
            {
                return _GenerateInstructions.ProjectNameStartedWithUpperCase;
            }
        }        
        public string Package
        {
            get { return _GenerateInstructions.ProjectName.ToLower(); }
        }
        #endregion

        #region Public Methods
        public TVDesigner.Entities.Elements.Screen GetScreenByName(string name)
        {
            foreach (Screen s in _Screens)
            {
                if (s.Name.Equals(name))
                {
                    return s;
                }
            }
            return null;
        }

        public void AddScreen(Screen screen)
        {
            _Screens.Add(screen);
            screen.SetProject(this);
        }

        public void RemoveScreen(Screen screen)
        {
            foreach (Screen sc in _Screens)
            {
                foreach (HButton hb in sc.HButtons)
                {
                    if (hb.ScreenName != null && hb.ScreenName.Equals(screen.Name))
                    {
                        hb.ScreenName = null;
                    }
                }

                //if (sc.ScreenBlue.Equals(screen.Name))
                //{
                //    sc.ScreenBlue = null;
                //}
                //else if (sc.ScreenGreen.Equals(screen.Name))
                //{
                //    sc.ScreenGreen = null;
                //}
                //else if (sc.ScreenRed.Equals(screen.Name))
                //{
                //    sc.ScreenRed = null;
                //}
                //else if (sc.ScreenYellow.Equals(screen.Name))
                //{
                //    sc.ScreenYellow = null;
                //}
            }

            _Screens.Remove(screen);
        }

        #endregion


    }
}
